﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit"    
    xmlns:BadHabit_Factory_Controls="clr-namespace:BadHabit.Factory.Controls"    
    xmlns:BadHabit_Factory="clr-namespace:BadHabit.Factory"   
    xmlns:BadHabit_WPFTools="clr-namespace:BadHabit.WPFTools;assembly=BadHabit.WPFTools"
    xmlns:props="clr-namespace:BadHabit.Factory.Properties"
    
    >

  
    
    <ControlTemplate x:Key="NormalCell" TargetType="{x:Type dg:DataGridCell}">        
        <Border x:Name="border"
                    Background="{TemplateBinding Background}"                                         
                    BorderThickness="0"                   
                    SnapsToDevicePixels="True">
            <ContentPresenter                                  
                        SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
        </Border>        
    </ControlTemplate>

    <!-- YOU MAY ASK, WAY I DID THAT.
         WELL TO SHOW THE DETAIL BUTTON ON THE CELLS AND UP/DOWN ARROW I NEED IT
    -->
    <Style TargetType="{x:Type dg:DataGridRow}">
        <Setter Property="BorderThickness" Value="0,0,0,1"/>
        <Style.Triggers>
            <Trigger Property="Selector.IsSelected" Value="True">
                <Setter Property="Panel.ZIndex" Value="99"/>
            </Trigger>
            <Trigger Property="Selector.IsSelected" Value="False">
                <Setter Property="Panel.ZIndex" Value="0"/>
            </Trigger>
        </Style.Triggers>
    </Style>
    
    <ControlTemplate x:Key="DetailCell" TargetType="{x:Type dg:DataGridCell}">
        <Border     x:Name="border"
                    BorderThickness="0"
                    Background="{TemplateBinding Background}"                     
                    SnapsToDevicePixels="True">
            <Grid>
                
                <Border
                        x:Name="popupDetail"
                        Width="80" Height="20"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Bottom" Margin="0,0,0,-20"
                        Background="#d6e4c3" BorderBrush="LightGray"                     
                        CornerRadius="0,0,3,3" BorderThickness="1,0,1,1" Padding="3">
                    
                    <StackPanel Orientation="Horizontal">
                        <TextBlock FontSize="{StaticResource BasicFontSize}" Margin="5,0,0,0">
                            <Hyperlink                                 
                                FocusManager.IsFocusScope="True"
                                KeyboardNavigation.IsTabStop="False"
                                Command="BadHabit_Factory:FactoryCommands.OpenItemDetail">
                                <TextBlock Text="{x:Static props:Resources.Details}"/>                               
                            </Hyperlink>
                        </TextBlock>

                        <!--<TextBlock FontSize="{StaticResource BasicFontSize}" Margin="5,0,0,0">
                            <Hyperlink                                 
                                FocusManager.IsFocusScope="True"
                                KeyboardNavigation.IsTabStop="False"
                                Command="BadHabit_Factory:FactoryCommands.OpenItemDetail">
                                Remove
                            </Hyperlink>
                        </TextBlock>-->
                    </StackPanel>
                    
                    
                    
                    <Border.Style>
                        <Style>
                            <Setter Property="Border.Visibility" Value="Collapsed"/>    
                        </Style>                        
                    </Border.Style>
                </Border>
                
                <ContentPresenter                                                
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"                    
                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
            </Grid>

        </Border>
        <ControlTemplate.Triggers>            
            <Trigger Property="IsEditing" Value="True">
                <Setter TargetName="popupDetail" Property="Border.Visibility" Value="Visible"/>
            </Trigger>
            <Trigger Property="IsFocused" Value="True">
                <Setter TargetName="popupDetail" Property="Border.Visibility" Value="Visible"/>
            </Trigger>            
        </ControlTemplate.Triggers>        
    </ControlTemplate>

    <ControlTemplate x:Key="UpDownCell" TargetType="{x:Type dg:DataGridCell}">
        <Border
                    Background="{TemplateBinding Background}"                     
                    BorderThickness="0"                    
                    SnapsToDevicePixels="True">
            <Grid>
                <Button x:Name="upButton" Margin="0,-20,0,0" VerticalAlignment="Top" HorizontalAlignment="Left"
                        FocusManager.IsFocusScope="True" IsTabStop="False">
                    <Button.Style>
                        <Style BasedOn="{StaticResource UpButton}" TargetType="Button">
                            <Setter Property="Button.Visibility" Value="Collapsed"/>                            
                        </Style>                        
                    </Button.Style>
                </Button>
                
                <Button x:Name="downButton" Margin="0,0,0,-20" VerticalAlignment="Bottom" HorizontalAlignment="Left"
                        FocusManager.IsFocusScope="True"  IsTabStop="False">
                    <Button.Style>
                        <Style BasedOn="{StaticResource DownButton}" TargetType="Button">
                            <Setter Property="Button.Visibility" Value="Collapsed"/>                            
                        </Style>
                    </Button.Style>
                </Button>

                <ContentPresenter   
                    x:Name="presenter"
                    
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                    HorizontalAlignment="Right"
                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />        
            </Grid>        
        </Border>
        <ControlTemplate.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsSelected" Value="True"/>
                    <!--<Condition Property="IsMouseOver" Value="True"/>-->
                    <Condition SourceName="upButton" Property="Button.IsEnabled" Value="True"/>
                </MultiTrigger.Conditions>
                <Setter TargetName="upButton" Property="Button.Visibility" Value="Visible" />                
            </MultiTrigger>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsSelected" Value="True"/>
                    <!--<Condition Property="IsMouseOver" Value="True"/>-->
                    <Condition SourceName="downButton" Property="Button.IsEnabled" Value="True"/>
                </MultiTrigger.Conditions>
                <Setter TargetName="downButton" Property="Button.Visibility" Value="Visible" />
            </MultiTrigger>

        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="DetailCellStyle" TargetType="{x:Type dg:DataGridCell}">
        <Setter Property="FontFamily" Value="{StaticResource BasicFont}"/>
        <Setter Property="FontSize" Value="{StaticResource NeedToSeeFontSize}"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Template" Value="{StaticResource DetailCell}" />        
        <Style.Triggers>
            <Trigger Property="IsReadOnly" Value="True">
                <Setter Property="Focusable" Value="False" />
            </Trigger>
            <Trigger Property="IsFocused" Value="True">                
                <Setter Property="Background" Value="#d6e4c3"/>
            </Trigger>
            <Trigger Property="IsEditing" Value="True">                
                <Setter Property="Background" Value="#d6e4c3"/>
            </Trigger>
        </Style.Triggers>
    </Style>
    
    
    

    <Style x:Key="MoveUpDownCellStyle" TargetType="{x:Type dg:DataGridCell}">
        <Setter Property="FontFamily" Value="{StaticResource BasicFont}"/>
        <Setter Property="FontSize" Value="{StaticResource BasicFontSize}"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Template" Value="{StaticResource UpDownCell}" />            
     
    </Style>

    <Style TargetType="{x:Type dg:DataGridCell}">
        <Setter Property="FontFamily" Value="{StaticResource BasicFont}"/>
        <Setter Property="FontSize" Value="{StaticResource BasicFontSize}"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>        
        <Setter Property="Template" Value="{StaticResource NormalCell}"/>                            
        <Style.Triggers>            
            <Trigger Property="IsFocused" Value="True">                                
                <Setter Property="Background" Value="#d6e4c3"/>
            </Trigger>
            <Trigger Property="IsEditing" Value="True">                
                <Setter Property="Background" Value="#d6e4c3"/>                
            </Trigger>
            <Trigger Property="IsReadOnly" Value="True">
                <Setter Property="IsTabStop" Value="False" />                
                <Setter Property="Focusable" Value="False" />
            </Trigger>            
        </Style.Triggers>    
    </Style>
    
    <Style x:Key="RightAlignCellStyle" TargetType="dg:DataGridCell" BasedOn="{StaticResource {x:Type dg:DataGridCell}}" >
        <Setter Property="HorizontalContentAlignment" Value="Right"/>
        
    </Style>
    
    <Style x:Key="RightAlignBoldCellStyle" TargetType="dg:DataGridCell" BasedOn="{StaticResource {x:Type dg:DataGridCell}}" >
        <Setter Property="FontWeight" Value="Bold"/>
        <Setter Property="HorizontalContentAlignment" Value="Right"/>
    </Style>
    
    <Style x:Key="CenterAlignCellStyle" TargetType="dg:DataGridCell" BasedOn="{StaticResource {x:Type dg:DataGridCell}}" >
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
    </Style>
    
    <Style x:Key="StretchAlignCellStyle" TargetType="dg:DataGridCell" BasedOn="{StaticResource {x:Type dg:DataGridCell}}" >
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
    </Style>
 
    <Style TargetType="{x:Type BadHabit_WPFTools:DataGrid}">
        <Setter Property="AlternatingRowBackground" Value="#FBFBFB"/>
        <Setter Property="Margin" Value="2,2,2,2"/>
        <Setter Property="GridLinesVisibility" Value="Horizontal"/>
        <Setter Property="VerticalGridLinesBrush" Value="{StaticResource WaterMarkBrush}"/>
        <Setter Property="HorizontalGridLinesBrush" Value="{StaticResource WaterMarkBrush}"/>
        <Setter Property="Background" Value="White"/>
        <Setter Property="RowHeaderWidth" Value="0"/>
        <Setter Property="RowHeight" Value="24"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="SelectionMode" Value="Single"/>
        <Setter Property="SelectionUnit" Value="FullRow"/>                
        
    </Style>


    <Style TargetType="{x:Type dg:DataGridHeaderBorder}" >
        <Setter Property="Background" Value="{StaticResource LightStrongBrush}" />
        <Setter Property="CornerRadius" Value="5,5,0,0" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Margin" Value="0" />
    </Style>
    
    <Style TargetType="{x:Type dg:DataGridColumnHeader}" >
        <Setter Property="Background" Value="{StaticResource LightStrongBrush}" />
        <Setter Property="Foreground" Value="{StaticResource DarkTextBrush}" />
        <Setter Property="Padding" Value="4,6,4,6" />
    </Style>

    <Style x:Key="RightAlignColumnStyle" TargetType="{x:Type dg:DataGridColumnHeader}" BasedOn="{StaticResource {x:Type dg:DataGridColumnHeader}}" >
        <Setter Property="HorizontalContentAlignment" Value="Right"/>
    </Style>


    

    

    <Style TargetType="{x:Type GridViewColumnHeader}">
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="Foreground" Value="{StaticResource DarkTextBrush}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
                    <Grid SnapsToDevicePixels="true"
                          Background="{TemplateBinding Background}">

                        <Border BorderThickness="{TemplateBinding BorderThickness}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                Padding="{TemplateBinding Padding}"
                                Margin="1,0,1,0">
                            <ContentPresenter x:Name="HeaderContent"
                                              Margin="5,0,0,1"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              RecognizesAccessKey="True"
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        </Border>

                        <Thumb
                                x:Name="PART_HeaderGripper"
                                HorizontalAlignment="Right"
                                Margin="0"
                                Width="2" >
                            <Thumb.Style>
                                <Style TargetType="Thumb">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="{x:Type Thumb}">
                                                <Border Width="3" Background="Transparent"/>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </Thumb.Style>
                        </Thumb>

                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter TargetName="PART_HeaderGripper" Property="Background" Value="Transparent"/>
                            <Setter Property="Background" Value="#FDFDFD"/>
                        </Trigger>
                        <Trigger Property="IsPressed" Value="true">

                            <Setter TargetName="PART_HeaderGripper" Property="Visibility" Value="Hidden"/>

                            <Setter TargetName="HeaderContent" Property="Margin" Value="1,1,0,0"/>
                            <Setter Property="Background" Value="#FDFDFD"/>
                            <Setter Property="BorderBrush" Value="#FDFDFD"/>
                        </Trigger>
                        <Trigger Property="Height" Value="Auto">
                            <Setter Property="MinHeight" Value="20"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="Role" Value="Floating">
                <Setter Property="Opacity" Value="0.7"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
                            <Canvas Name="PART_FloatingHeaderCanvas" />
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property="Role" Value="Padding">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
                            <Grid Background="{TemplateBinding Background}" SnapsToDevicePixels="true">

                                <Border BorderThickness="{TemplateBinding BorderThickness}"
                                        BorderBrush="{TemplateBinding BorderBrush}"
                                        Padding="{TemplateBinding Padding}" 
                                        Margin="1,0,1,0"/>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="Height" Value="Auto">
                                    <Setter Property="MinHeight" Value="20"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>

    
        <Style x:Key="TransparentEditingElementStyle" TargetType="TextBox" BasedOn="{x:Static dg:DataGridTextColumn.DefaultEditingElementStyle}">
            <Setter Property="Background" Value="Transparent"/>
        </Style>


    <Style x:Key="NeedToSeeTextElementStyle" TargetType="TextBlock" BasedOn="{x:Static dg:DataGridTextColumn.DefaultElementStyle}">
        <Setter Property="FontSize" Value="{StaticResource NeedToSeeFontSize}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="TextWrapping" Value="Wrap"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
    </Style>

    <Style x:Key="NeedToSeeTextEditingElementStyle" TargetType="TextBox" BasedOn="{x:Static dg:DataGridTextColumn.DefaultEditingElementStyle}">
        <Setter Property="FontSize" Value="{StaticResource NeedToSeeFontSize}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="TextWrapping" Value="Wrap"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
    </Style>



</ResourceDictionary>